package com.cloudcc.mobile.parser;

import java.util.ArrayList;
import java.util.List;

import com.cloudcc.mobile.entity.Module;
import com.cloudcc.mobile.entity.ModuleMessage;
import com.cloudcc.mobile.util.UrlTools;

public class ModuleMessageParser {
	public static List<ModuleMessage> getModuleMessages(List<Module> list) {
		List<ModuleMessage> moduleMessages = new ArrayList<ModuleMessage>();
		for (int i = 0; i < list.size(); i++) {
			String name = list.get(i).getLabel();
			String id = list.get(i).getSeq();
			if (name.equals("CloudCC")) {
				id = "" + 3;
			} else if (id == null) {
				int num = (int) (Math.random() * 6) + 1;
				while (num == 9) {
					num = (int) (Math.random() * 6) + 1;
				}
				id = "" + num;
			}
			String url = UrlTools.weixinUrl
					+ UrlTools.getModuleUrl(list.get(i).getId(), list.get(i)
							.getLabel());
			ModuleMessage mes = new ModuleMessage(name, url, "menu" + id, 0);
			moduleMessages.add(mes);
		}
		return moduleMessages;
	}
}
